﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UtilZ.Dotnet.Ex.Communication.Net.MQBase
{
    /// <summary>
    /// MQ连接信息
    /// </summary>
    public class MQBrokerInfo
    {
        /// <summary>
        /// 连接地址
        /// </summary>
        public string BrokerUrl { get; private set; }

        /// <summary>
        /// 用户名
        /// </summary>
        public string Password { get; private set; }

        /// <summary>
        /// 密码
        /// </summary>
        public string UserName { get; private set; }




        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="brokerUrl">连接地址</param>
        public MQBrokerInfo(string brokerUrl)
            : this(brokerUrl, null, null)
        {
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="brokerUrl">连接地址</param>
        /// <param name="userName">用户名</param>
        /// <param name="pwd">密码</param>
        public MQBrokerInfo(string brokerUrl, string userName, string pwd)
        {
            this.BrokerUrl = brokerUrl;
            this.UserName = userName;
            this.Password = pwd;
        }

        /// <summary>
        /// 重写Equals[相等返回true;不相等返回false]
        /// </summary>
        /// <param name="obj">比较对象</param>
        /// <returns>相等返回true;不相等返回false</returns>
        public override bool Equals(object obj)
        {
            var info = obj as MQBrokerInfo;
            if (info == null)
            {
                return false;
            }

            if (info == this)
            {
                return true;
            }

            return object.Equals(info.BrokerUrl, this.BrokerUrl);
        }

        /// <summary>
        /// 重写GetHashCode
        /// </summary>
        /// <returns>HashCode</returns>
        public override int GetHashCode()
        {
            if (this.BrokerUrl == null)
            {
                return string.Empty.GetHashCode();
            }
            else
            {
                return this.BrokerUrl.GetHashCode();
            }
        }

        
    }
}
